package fi.laurea.datalogger;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import com.google.gson.Gson;
import fi.laurea.jsonbus.Receiver;
import fi.laurea.jsonbus.ReceiverListener;

public class LoggerUI extends JPanel implements ReceiverListener{
	Receiver receiver;
	private JTextArea area;
	private JTextArea area2;
	private Gson gson;


	public LoggerUI(){
		receiver = new Receiver ("logger","matti",this);
		this.area = new JTextArea();
		this.area = new JTextArea();
		this.area.setText("-:-");
		this.gson = new Gson();
		this.add(area);
		
	}
	@Override
	public void prosessGloballMessage(String json) {
		DataMessage message = (DataMessage) gson.fromJson(json, DataMessage.class);
		String values ="";
		String names ="";
		
		for(String s : message.getValues()){
			values += s;
		}
		for(String n : message.getNames()){
			names += n;
			
		}
		
		this.area.setText(values);
		this.area2.setText(names);
		
	}
	@Override
	public void prosessPrivateMessage(String json) {
		// TODO Auto-generated method stub
	
	}
	public static void main (String[] args){
		JFrame frame = new JFrame();
		frame.add(new LoggerUI());
		frame.setVisible(true);
	}
}